// Copyright 2022 jeff.li. and/or its affiliates.

#include <gtest/gtest.h>
#include <tbir/runtime/container.h>

namespace tbir::runtime {

    TEST(Iterator, Constructor) {
        {
            List container{"hello", "hello", 3, List{"bb"}, Dict{{"hello", "good"}}, Set{"jj"}};
            Iterator iter = container.iter();
            RTValue xx;
            List new_con;
            while (iter.HasNext()) {
                xx = iter.Next();
                new_con.append(xx);
                std::cout << "xx: " << xx << std::endl;
            }
            EXPECT_EQ(new_con, container);
        }
        {
            Set container{"hello", "hello", 3};
            Iterator iter = container.iter();
            RTValue xx;
            Set new_con;
            while (iter.HasNext()) {
                xx = iter.Next();
                new_con.add(xx);
                std::cout << "xx: " << xx << std::endl;
            }
            EXPECT_EQ(new_con, container);
        }
        {
            Set container{"hello", "hello", 3};
            Iterator iter = container.iter();
            RTValue xx;
            Set new_con;
            bool has_next = iter.HasNext();
            while (has_next) {
                xx = iter.Next(&has_next);
                new_con.add(xx);
                std::cout << "xx: " << xx << std::endl;
            }
            EXPECT_EQ(new_con, container);
        }
    }

}  // namespace tbir::runtime
